package com.itzxx.huazhun.ui.testing

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.chad.library.adapter4.BaseQuickAdapter
import com.itzxx.huazhun.databinding.FragmentTestingBinding
import com.itzxx.huazhun.ui.MainViewModel
import com.itzxx.huazhun.ui.testing.data.TestingBean
import com.itzxx.huazhun.ui.testing.newbuild.TestingNewBuildActivity
import com.itzxx.library_base_ktx.base.fragment.BaseVmDbFragment
import com.itzxx.library_base_ktx.ext.view.addLinearAdapter

class TestingFragment : BaseVmDbFragment<TestingViewModel, FragmentTestingBinding>() {



    //获取共享ViewModel
    private val mainSharedViewModel: MainViewModel by activityViewModels()


    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun lazyLoadData() {
        mDatabind.userPermissionInfo = mainSharedViewModel.userPermissionLiveData.value
        mDatabind.userInfo = mainSharedViewModel.userInfoLiveData.value
        if (mainSharedViewModel.isOfflineLiveData.value) {
            mDatabind.cvActionebar.visibility = View.GONE
        }
    }

    override fun createObserver() {
        mainSharedViewModel.run {
            userInfoLiveData.observe(this@TestingFragment) {
                mDatabind.userInfo = it
            }

            userPermissionLiveData.observe(this@TestingFragment) {
                mDatabind.userPermissionInfo = it
            }

            isOfflineLiveData.observe(this@TestingFragment){
                mDatabind.cvActionebar.visibility = View.GONE
            }
        }
        //选中设备
        mViewModel.run {
            bleDeviceCheckLiveData.observe(this@TestingFragment){
            }
        }
    }

    override fun databind2ViewModel() {
        super.databind2ViewModel()
        mDatabind.viewmodel = mViewModel
    }

    override fun isApplyDefaultWaitDialog(): Boolean {
        return true
    }
}